package com.guyaning.deyson_core.core.delegates.web;

import android.os.Build;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

/**
 * Created by Administrator on 2018/7/7.
 */

public class WebviewInilalizer {

    public WebView createWebView(WebView webView) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }

        //设置不能横向滚动
        webView.setHorizontalScrollBarEnabled(false);

        //设置不能纵向滑动
        webView.setVerticalScrollBarEnabled(false);

        //设置可以截图
        webView.setDrawingCacheEnabled(true);

        //设置关闭长按时间
        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });

        //初始化settings
        WebSettings settings = webView.getSettings();

        settings.setJavaScriptEnabled(true);

        String ua = settings.getUserAgentString();

        settings.setUserAgentString(ua + "latte");

        //设置隐藏缩放按钮
        settings.setBuiltInZoomControls(false);
        settings.setDisplayZoomControls(false);

        //设置禁止缩放
        settings.setSupportZoom(false);

        //文件权限
        settings.setAllowFileAccess(true);
        settings.setAllowFileAccessFromFileURLs(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
        settings.setAllowContentAccess(true);

        //设置缓存
        settings.setAppCacheEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);

        return webView;
    }

}

